import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { i18n } from '@/locales';
import { userSearch } from '@/api/user-data';
import { ref } from 'vue';
export const userList = ref();
/**
 * columns
 */
export type TableListItem = {
  id;
  serial;
  name;
  leader;
  createTime;
  desp;
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    // @ts-ignore
    title: `${i18n.global.t('specimen.topic')}组编号`,
    field: 'serial',
  },
  {
    // @ts-ignore
    title: `${i18n.global.t('specimen.topic')}组名称`,
    field: 'name',
    formItemProps: {
      labelWidth: 120,
    },
  },
  {
    // @ts-ignore
    title: `${i18n.global.t('specimen.topic')}组负责人`,
    field: 'leader',
    formatter: ({ cellValue }) => {
      return userList.value?.find((item) => item?.value === cellValue)?.label;
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        request: async () => {
          const res = await userSearch({
            paging: false,
          });
          return (userList.value = res.result.map((item) => ({
            label: item.name,
            value: item.id,
          })));
        },
      },
      labelWidth: 120,
    },
  },
  {
    title: '创建时间',
    field: 'createTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    hideInSearch: true,
  },
  {
    title: '描述',
    field: 'desp',
    hideInSearch: true,
  },
];
